<script type="text/javascript">
    {literal}
        $(document).ready(function() {
            $("#fulltext").keyup(function(event){
                if(event.keyCode == 13){
                    setFulltext($('#fulltext').val(),'list_of_tasks_fulltext')
                }
            });
            $("#fulltext").focus();
        });
    {/literal}
</script>
<h2 class="pageTitle">List of tasks</h2>
{include $data.pathToError}
<div class="menu-list">
    Fulltext search: <input id="fulltext" type="text" value="{if $data.currentFulltext != ''}{$data.currentFulltext}{/if}" /><input value="Search" type="button" onclick="setFulltext($('#fulltext').val(),'list_of_tasks_fulltext')" />
    Responsible/Worker filter: 
    <select size="1" onchange="filter('responsible_or_worker',this.value,'list_of_tasks_filter')">
        <option value="-1">-</option>
        {foreach $data.responsibles as $key => $responsible}
            <option {if $smarty.session.list_of_tasks_filter.responsible_or_worker==$responsible.users_id}selected="selected"{/if} value="{$responsible.users_id}">{$responsible.surname}, {$responsible.name}</option>
        {/foreach}
    </select>
    {if $smarty.session.user.user_type_id == $smarty.const.USER_TYPE_CLIENT}
    Client: 
    <select size="1" onchange="filter('client',this.value,'list_of_tasks_filter')">
        <option value="">Please select</option>
        {foreach from=$data.clients item="client"}
            <option {if $smarty.session.user.user_type_id!=$smarty.const.USER_TYPE_CLIENT && $client.bad_payer==1}class="badPayer"{/if} {if isset($smarty.session.user.clientFilter) && $smarty.session.user.clientFilter==$client.klient_id}selected="selected"{/if} value="{$client.klient_id}">{$client.name}</option>
        {/foreach}
    </select>&nbsp;
    {/if}
    Status of task:
    <select size="1" onchange="filter('status',this.value,'list_of_tasks_filter')">
        <option value="">Please select</option>
        {foreach from=$data.statuses item="status"}
            <option value="{$status.id_stav}">{$status.stav}</option>
        {/foreach}
    </select>&nbsp;
    <div style="float: right;">
        <a target="_blank" href="{$data.root}excel.php?table=list_of_tasks">
            <img src="{$data.root}images/excel.png" title="export to excel" alt="" height="20" width="20" />
        </a>
    </div>
</div>
{if $data.currentFilter || $data.currentFulltext!=''}
    <div class="menu-list bgDark">
        <b>Current filter:</b> 
        <ul>
            {foreach $data.currentFilter as $filter => $value}
                <li>{$filter} = <i>{$value}</i> [<a href="javascript: cancelFilter('{$filter}','list_of_tasks_filter')" class="baseLink">Cancel</a>]</li>
            {/foreach}
            {if $data.currentFulltext != ''}
                <li>Fulltext = <i>{$data.currentFulltext}</i> [<a href="javascript: cancelFulltext('list_of_tasks_fulltext')" class="baseLink">Cancel</a>]</li>
            {/if}
        </ul>
    </div>
{/if}
<table class="list">
    <tr>
        <th><a href="javascript: order('rate','list_of_tasks_order')">% {if $data.currentOrder.0=="rate"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
        <th><a href="javascript: order('title','list_of_tasks_order')">Name {if $data.currentOrder.0=="title"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
        <th><a href="javascript: order('client','list_of_tasks_order')">Client {if $data.currentOrder.0=="client"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
        <th><a href="javascript: order('creator','list_of_tasks_order')">Who add {if $data.currentOrder.0=="creator"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a><br/><a href="javascript: order('added','list_of_tasks_order')">When add {if $data.currentOrder.0=="added"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
        <th><a href="javascript: order('updater','list_of_tasks_order')">Who update {if $data.currentOrder.0=="updater"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a><br/><a href="javascript: order('updated','list_of_tasks_order')">When update {if $data.currentOrder.0=="updated"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
        <th><a href="javascript: order('deadline','list_of_tasks_order')">Deadline {if $data.currentOrder.0=="deadline"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
        <th><a href="javascript: order('responsible','list_of_tasks_order')">Responsible {if $data.currentOrder.0=="responsible"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a><br/><a href="javascript: order('worker','list_of_tasks_order')">Worker {if $data.currentOrder.0=="worker"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
        <th><a href="javascript: order('type','list_of_tasks_order')">Task type {if $data.currentOrder.0=="type"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
        <th><a href="javascript: order('status','list_of_tasks_order')">Status {if $data.currentOrder.0=="status"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
        <th><a href="javascript: order('priority','list_of_tasks_order')">! {if $data.currentOrder.0=="priority"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
                {*<th><a href="javascript: order('problem_type','list_of_tasks_order')">Type of problem {if $data.currentOrder.0=="problem_type"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>*}
                {*<th><a href="javascript: order('consult','list_of_tasks_order')">Consult {if $data.currentOrder.0=="consult"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>*}
                {*<th>Posts</th>*}
    </tr>
    {assign var=counter value=1}
    {foreach $data.tasks as $key => $task}
        {if $task.state == 3}
            {assign var=bgClass value='bgRed'}
        {elseif $task.state == 2}
            {assign var=bgClass value='bgOrange'}
        {elseif $task.state == 1}
            {assign var=bgClass value='bgYellow'}
        {else}
            {if $counter==1}
                {assign var=bgClass value='bgDark'}
            {else}
                {assign var=bgClass value='bgLight'}
            {/if}
        {/if}
        <tr id="row_{$task.taskId}" class="{$bgClass} row" onclick="selectRow('{$task.taskId}','{$bgClass}')">
            {if $counter==1}
                {assign var=counter value=2}
            {else}
                {assign var=counter value=1}
            {/if}
            {*<td style="width:20px">
            {if $task.creator == $smarty.session.user.user_id}
            <a href="javascript: deleteTask({$task.taskId})">
            <img height="16" width="16" src="{$smarty.const.PATH_TO_IMAGES}delete.png" />
            </a>
            {/if}
            </td>*}
            {if $task.rate > 100}
                {assign var=bgStyle value='bgRedTd'}
            {elseif $task.rate > 70}
                {assign var=bgStyle value='bgOrangeTd'}
            {else}
                {assign var=bgStyle value='bgWhite'}
            {/if}
            <td class="{$bgStyle}">
                {if $task.rate == -1}
                    -
                {else}
                    {$task.rate}
                {/if}
            </td>
            <td style="width: 285px"><a class="filterLink" href="{$data.root}?input=edit_task&task={$task.taskId}">{$task.title}</a></td>
            <td><a class="filterLink" href="javascript: filter('client','{$task.client}','list_of_tasks_filter')">{$task.client_info.name}</a></td>
            <td class="center"><a class="filterLink" href="javascript: filter('creator','{$task.creator}','list_of_tasks_filter')">{$task.creator_info.name} {$task.creator_info.surname}</a><br/><a class="filterLink" href="javascript: filter('added','{$task.added}','list_of_tasks_filter')">{$task.created_format}</a></td>
            <td class="center">
                {if $task.updater_isset==1}
                    <a class="filterLink" href="javascript: filter('updater','{$task.updater}','list_of_tasks_filter')">{$task.updater_info.name} {$task.updater_info.surname}</a><br/><a class="filterLink" href="javascript: filter('updated','{$task.updated}','list_of_tasks_filter')">{$task.updated_format}</a>
                {else}
                    -
                {/if}
            </td>
            <td><a class="filterLink" href="javascript: filter('deadline','{$task.deadline}','list_of_tasks_filter')">{$task.deadline_format}</a></td>
            <td><a class="filterLink" href="javascript: filter('responsible','{$task.responsible}','list_of_tasks_filter')">{$task.responsible_info.name} {$task.responsible_info.surname}</a><br/>
                {if $task.worker!=-1}
                    <a class="filterLink" href="javascript: filter('worker','{$task.worker}','list_of_tasks_filter')">{$task.worker_info.name} {$task.worker_info.surname}</a>
                {else}
                    -
                {/if}
            </td>
            <td style="width: 10em"><a class="filterLink" href="javascript: filter('type','{$task.type}','list_of_tasks_filter')">{$task.type_info.type_of_record}</a></td>
            <td><a class="filterLink" href="javascript: filter('status','{$task.status}','list_of_tasks_filter')">{$task.status_info.stav}</a></td>
            <td style="width: 2em"><a class="filterLink" href="javascript: filter('priority','{$task.priority}','list_of_tasks_filter')">{$task.priority_info.Priorita}</a></td>
            {*<td style="width: 8em"><a class="filterLink" href="javascript: filter('problem_type','{$task.problem_type}','list_of_tasks_filter')">{$task.problem_type_info.problem}</a></td>
            <td>
            <a class="filterLink" href="javascript: filter('consult','{$task.consult}','list_of_tasks_filter')">
            {if $task.consult ==1}
            Yes
            {else}
            No
            {/if}
            </a>
            </td>*}
            {*<td>
            {$task.posts_in_phorum}
            </td>*}
        </tr>
    {/foreach}
</table>
<div class="menu-list">
    <span class="pager">{$data.pager}</span>
    Records per page
    <select class="pager" size="1" onchange="changeRecordsPerPage(this.value, 'list_of_tasks_pager')">
        <option {if $smarty.session.list_of_tasks_pager==20}selected="selected"{/if} value="20">20</option>
        <option {if $smarty.session.list_of_tasks_pager==50}selected="selected"{/if} value="50">50</option>
        <option {if $smarty.session.list_of_tasks_pager==100}selected="selected"{/if} value="100">100</option>
    </select>
    Count: {$data.total_count}
    {*<span><b>Current ordering:</b> <i>{$data.currentOrder}</i> [<a class="baseLink" href="javascript: order('CLEAR','list_of_tasks_order')">Clear ordering</a>]</span>*}
</div>